
 /**  
 * Project Name:zhonghecrm  
 * File Name:SysCompanyController.java  
 * Package Name:com.crm.controller  
 * Date:2016年10月26日下午2:11:58   
 *  
*/  
  
package com.crm.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crm.annotation.SystemServiceLog;
import com.crm.model.SysDuty;
import com.crm.model.entity.Tree;
import com.crm.service.SysDutyService;
import com.crm.util.AopConfig;
import com.crm.util.JsonUtil;
import com.crm.util.ResponseUtil;
import com.github.pagehelper.Page;

/**  
 * ClassName:SysCompanyController <br/>  
 * Function: TODO ADD FUNCTION. <br/>  
 * Reason:   TODO ADD REASON. <br/>  
 * Date:     2016年10月26日 下午2:11:58 <br/>  
 * @author   hanlinxiu  
 * @version    
 * @since    JDK 1.8  
 * @see        
 */
@Controller
@RequestMapping("/duty")
public class SysDutyController {
	
	@Autowired
	private SysDutyService sysDutyService;
	
	@RequestMapping("/index")
	public String index(Page<SysDuty> page,ModelMap map){
		return "sysconf/duty";
	}
	
	@RequestMapping("/addNewRecord")
	@ResponseBody
	public Map<String, Object> addNewRecord(SysDuty record){
		
		Map<String, Object> map = new HashMap<>();
		
		sysDutyService.insert(record);
		
		map.put("status", "success");
		map.put("msg", "新增成功！");
		
		return map;
	}
	
	@RequestMapping("/deleteRecord")
	@ResponseBody
	public Map<String, Object> deleteRecord(SysDuty record){
		
		Map<String, Object> map = new HashMap<>();
		
		record.setDeleteMark(0);
		sysDutyService.updateByPrimaryKey(record);
		
		map.put("status", "success");
		map.put("msg", "删除成功！");
		
		return map;
	}
	
	@SystemServiceLog(description=AopConfig.DUTY+AopConfig.UPDATE,type=AopConfig.UPDATE)
	@RequestMapping("/updateRecord")
	@ResponseBody
	public Map<String, Object> updateRecord(SysDuty duty){
		
		Map<String, Object> map = new HashMap<>();
		
		sysDutyService.updateByPrimaryKey(duty);
		
		map.put("status", "success");
		map.put("msg", "修改成功！");
		
		return map;
	}
	
	@RequestMapping("/getAll")
	@ResponseBody
	public Map<String, Object> getAll(Page<SysDuty> page, SysDuty record){
		
		Map<String, Object> map = new HashMap<>();
		
		Page<SysDuty> list = (Page<SysDuty>)sysDutyService.selectAll(page, record);
		
		map.put("list", list);
		map.put("status", "success");
		map.put("msg", "获取成功！");
		
		return map;
	}
	
	@RequestMapping("/getByDeptId")
	@ResponseBody
	public Map<String, Object> getByDeptId(String departmentId){
		
		Map<String, Object> map = new HashMap<>();
		
		List<SysDuty> list = sysDutyService.getByDepartmentId(departmentId);
		
		map.put("list", list);
		map.put("status", "success");
		map.put("msg", "获取成功！");
		
		return map;
	}
	
	@RequestMapping("/load")
	@ResponseBody
	public void load(HttpServletResponse response,HttpServletRequest request, Page<SysDuty> page, SysDuty t){
		Page<SysDuty> list = (Page<SysDuty>) sysDutyService.selectAll(page, t);
		ResponseUtil.resultPage(response,request,list);
	}
	
	@RequestMapping("/ajaxLoadDutyTree")
	public void ajaxLoadDutyTree(HttpServletResponse response,Tree tree){
		List<Tree> list = sysDutyService.selectByParm(tree);
		ResponseUtil.result(response, JsonUtil.toJsonStr(list));
	}
}
  
